package com.luckku.boot.controller;


import com.luckku.boot.common.api.ApiResult;
import com.luckku.boot.entity.ExamSite;
import com.luckku.boot.service.ExamSiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.luckku.boot.jwt.JwtUtil.USER_ID;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Luckku
 * @since 2022-10-13
 */
@RestController
@RequestMapping("/examSite")
public class ExamSiteController {

    @Autowired
    ExamSiteService examSiteService;

    /**
     * /examSite/getById
     * 获取考点信息信息
     *
     * @param examSite String
     * @return ApiResult<ExamSite>
     */
    @GetMapping(value = "/getById")
    public ApiResult<ExamSite> getById(@RequestParam(value = "examSiteId") String examSiteId) {
        ExamSite examSite = examSiteService.getById(examSiteId);
        if (examSite != null) {
            return ApiResult.success(examSite);
        }
        return ApiResult.failed("examSite not found");
    }

    /**
     * /examSite/getAllExams
     * 获取所有考试
     *
     * @return ApiResult<List < Exam>>
     */
    @GetMapping(value = "/getAllExams")
    public ApiResult<List<ExamSite>> getAllExams() {
        List<ExamSite> examSiteList = examSiteService.list();
        if (examSiteList != null || examSiteList.size() != 0) {
            return ApiResult.success(examSiteList);
        }
        return ApiResult.failed("examSiteList not found");
    }
}

